package service.impl;

import dao.UserDao;
import dao.impl.UserDaoImpl;
import domain.Book;
import domain.User;
import util.EncryptUtil;

import java.util.List;

public class UserServiceImpl implements service.UserService {
    @Override
    public void register(String avatar, String name, String username, String password, String email) {
        UserDao ud = new UserDaoImpl();
        ud.addUser(avatar, name, username, password, email);
    }

    @Override
    public Boolean checkPassowrd(String username, String password) {
        return new UserDaoImpl().checkPassword(username,password);
    }

    @Override
    public User getUserInfo(String username) {
        return new UserDaoImpl().getUserInfo(username);
    }

    @Override
    public User getUserInfo(int uid) {
        return new UserDaoImpl().getUserInfo(uid);
    }

    @Override
    public Boolean checkUserloginCookies(String psm, String usm,int uid) {
        UserDao ud = new UserDaoImpl();
        User userInfo = ud.getUserInfo(uid);
        if("".equals(userInfo.getPassword())||userInfo.getPassword()==null){
            return false;
        }
        return psm.equals(EncryptUtil.getMD5Str(userInfo.getPassword())) && usm.equals(EncryptUtil.getMD5Str(userInfo.getUsername()));
    }

    @Override
    public int getLastHistory(int uid) {
        return new UserDaoImpl().getLastHistory(uid);
    }

    @Override
    public List<Book> getUserbook(User user) {
        return new UserDaoImpl().getUserBook(user.getUid());
    }

    @Override
    public List<Integer> getCollect(User user) {
        return new UserDaoImpl().getCollect(user.getUid());
    }

    @Override
    public void addCollect(int uid, int bid) {
        new UserDaoImpl().addCollect(uid,bid);
    }

    @Override
    public void delCollect(int uid, int bid) {
        new UserDaoImpl().delCollect(uid,bid);
    }

}
